define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/withdrawal/index' + location.search,
                    // add_url: 'user/withdrawal/add',
                    // edit_url: 'user/withdrawal/edit',
                    del_url: 'user/withdrawal/del',
                    // multi_url: 'user/withdrawal/multi',
                    // import_url: 'user/withdrawal/import',
                    state_url: 'user/withdrawal/state',
                    table: 'user_withdrawal',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'sn', title: __('Sn'), operate: 'LIKE' },
                        { field: 'admin.nickname', title: __('公司'), operate: 'LIKE' },
                        { field: 'user.nickname', title: __('用户'), operate: 'LIKE' },
                        { field: 'money', title: __('Money'), operate: 'BETWEEN' },
                        { field: 'mobile', title: __('手机号'), operate: 'LIKE' },

                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'state', title: __('State'), searchList: { "1": __('State 1'), "2": __('State 2'), "3": __('State 3'), "4": __('State 4') }, formatter: Table.api.formatter.normal },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'pass',
                                    text: __('通过'),
                                    title: __('通过'),
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    url: $.fn.bootstrapTable.defaults.extend.state_url + "?ids={ids}&state=2",
                                    confirm: '确认审核通过吗？',
                                    callback: function (data) {
                                        // Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return row.state === "1";

                                    }
                                },
                                {
                                    name: 'reject',
                                    text: __('拒绝'),
                                    title: __('拒绝'),
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    url: $.fn.bootstrapTable.defaults.extend.state_url + "?ids={ids}&state=3",
                                    callback: function (data) {
                                        // Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    success: function (data, ret) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return row.state === "1";
                                    }
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            if (Config.state == 1) {
                Controller.api.bindevent();
            }
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
